<?php
/**
 * 项目级别的框架公共配置文件
 */

$config = [];

require APP_PATH . 'config.inc.php';

// 平台目录
define('PF_PATH', APPLICATION_PATH . 'pform/' . (isset($aliasArr[PFORM_NAME])? $aliasArr[PFORM_NAME] : PFORM_NAME ) . '/');
// 数据库相关
$config = array_merge($config, include(LIBRARY_PATH . 'db.php'));
// 本项目日志目录名
define('LOGPATH', '/data/log/' . GAME_SYMBOL);
$config +=  [

    'cola_log' => [
        'driver' => 'file',
        'dir' => LOGPATH . '/' . PFORM_NAME . '/' . date('Ym')
    ],

    'cola' => [
        'exception' => [
            'handlers' => [
                \Cola\ExceptionHandle::class
            ],
            'render' => \Cola\ExceptionRender::class,
            'isDebug' => APP_DEBUG,
            'errorLevel' => APP_DEBUG ? E_ALL : (E_ALL ^ E_NOTICE),
            'error_message' => '页面错误！请与客服联系～'
        ]
    ],
];
/*缓存是否开启*/
define('IS_CACHE', ! APP_DEV);
// 插入controller namespace
$config['_controller_namespaces'] = $config['_controller_namespaces'] ?? [];
$config['_controller_namespaces'] = array_merge($config['_controller_namespaces'], [
    '\\Application\\controller',
]);

// 插入model namespace
$config['_model_namespaces'] = $config['_model_namespaces'] ?? [];
$config['_model_namespaces'] = array_merge($config['_model_namespaces'], [
    "\\Application\\pform\\" . ($aliasArr[PFORM_NAME] ?? PFORM_NAME),
    '\\Application\\model',
]);
isset($_ENV['mysql']) or $_ENV['mysql'] = ['host'=>$config['_db']['host'], 'port'=>$config['_db']['port'], 'user'=>$config['_db']['user'], 'pwd'=>$config['_db']['password']];

$pf_config = true;

$cfile = CONFIG_PATH . '/alias_config/channel.php';
$channelArr = file_exists($cfile) ? (include($cfile) ?: []) : [];

$_ENV['ALIAS_CID'] = strtoupper(PFORM_NAME);
$_ENV['ALIAS_CHANNEL'] = $channelArr;

// 将平台的个性化配置合并到$config (注意：此处是追加合并，并非直接替换) (优化合并PFORM_NAME 配置，没有再合并alias映射的
if(file_exists(CONFIG_PATH . PFORM_NAME . '.php')){
    $config = array_merge_multi($config, include(CONFIG_PATH . PFORM_NAME . '.php'));
}elseif(file_exists(CONFIG_PATH . $aliasArr[PFORM_NAME] . '.php')){
    $config = array_merge_multi($config, include(CONFIG_PATH . $aliasArr[PFORM_NAME] . '.php'));
}else{
    $pf_config = false;
}
$config['pf_config'] = $pf_config;
// 替换成测试数据库连接，当为线上环境时$_ENV['databases']为空，则不执行array_merge，因为如果第二个为空则会重置$config里面的数字下标的元素
$_ENV['databases'] && $config = array_merge($config, $_ENV['databases']);
// 把config中的某些值设置为常量
define('HOSTS', $config['hosts'] ?? ''); // 默认cdn地址
